{extend name="public/base"}

{block name="title"}
维修店订单推送
{/block}

{block name="style"}
{css href="/static/wechat/css/index.css" /}
{css href="/static/wechat/popo/css/index_map.css" /}
{css href="/static/wechat/popo/css/order.css" /}
<style type="text/css">
    .msg_panel{position:fixed;top:0px;left:100%;width:100%;height:100%;background:#fff;overflow:auto;z-index:999;}
    .weui-popup__overlay{opacity:1;}
    .weui-dialog__btn{color:#0bb20c;font-size:0.8rem;}
    .weui-dialog, .weui-toast{box-shadow:0 0 3px 0 #000;}
    #box_order_list .weui-cell:before{z-index:999;}
    .so_btn {
        display: inline-block;
        width: 95%;
        background: #907050;
        text-align: center;
        height: 2rem;
        line-height: 2rem;
        font-size: .8rem;
        color: #fff;
        margin: 1rem auto 0 2.5%;
    }
    .push_foot1 {
        position: fixed;
        width: 100%;
        left: 0;
        bottom: 0;
        padding: 10px 0;
        text-indent: 15px;
    }
</style>
{/block}

{block name="body"}
<div class="pageControl index bg-f7">
    <div class="nav">
        <div class="msui_navTop">
            <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back_fff"></i></a>
            <h1 class="msui_navTop-title">推送订单</h1>
        </div>
    </div>
    <div class="msui_cell msui_cell-column" >
        <div class="msui_cell-item">
            <div class="msui_table">
                <div class="msui_tabCell-img msui_tableImg-circle">
                    <img src="{$order.logo|get_img_url}">
                </div>
                <div class="msui_tabCell-content">
                    <p class="fs085 cl-3333">{$order.repair_name|default=''}</p>
                    <p class="cl-9999">{$order.phone}</p>
                </div>

            </div>
        </div>
    </div>
    <div class="weui-content">
        <div id="box_order_list">
        {volist name="order.product_server" id="v"}
            <div class="weui-cell" sid="{$v.id}" goods_id="{$v.product_id}" goods_img="{$v.product_image}" expires_day="{$v.server_time}" title="{$v.product_name}">
                <div class="weui-label">
                    <img src="{$v.product_image}" alt="" />
                </div>
                <div class="weui-cell__bd weui-cell__bd1">
                    <p class="fs07">{$v.product_name}</p>
                    <p>售后保证{$v.server_time?$v.server_time.'天':'无售后'}</p>
                </div>
                <div class="weui-cell__ft list1">
                    <p>￥<b>{$v.product_price}</b></p>
                    <p class="cl-9999">× <span>{$v.product_num}</span></p>
                </div>
                <a href="javascript:;" class="weui-cell__ft list2">
                    <span class="fs22">-</span>
                </a>
            </div>
        {/volist}
        </div>
        <div class="push_foot">
            <div class="weui-cell__bd">
                <!--<a id="but_add_service" class="push_foot_btn" href="javascript:;">添加服务</a>-->
                <a id="but_goods" class="push_foot_btn" href="javascript:;">添加商品</a>
            </div>
        </div>
    </div>
    <div style="height: 50px;"></div>
    <div class="weui-cell push_foot1">
        <div class="weui-cell__bd">
            <p>合计 ：￥<span id="box_order_sum">0.00</span></p>
        </div>
        <a href="javascript:;" class="weui-cell__ft index1_btn" id="order_submit_but">
            <span>确认推送</span>
        </a>
    </div>
</div>

<!--add_service-->
<div id="page_add_service" class="msg_panel">
    <div class="pageControl index bg-f7">
        <div class="nav">
            <div class="msui_navTop">
                <a class="msui_navTop-back" href="javascript:;"><i class="micon-back_fff"></i></a>
                <h1 class="msui_navTop-title">添加服务</h1>
            </div>
        </div>
        <div class="weui-cells add">
            <div class="weui-cell">
                <div class="weui-label">
                    名称
                </div>
                <div class="weui-cell__bd">
                    <input name="s_name" type="text" class="weui-input" placeholder="请输入项目名称"/>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-label">
                    价格(元)
                </div>
                <div class="weui-cell__bd">
                    <input name="s_price" type="number" class="weui-input" placeholder="请设置单价" value="0" />
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-label">
                    数量
                </div>
                <div class="weui-cell__bd">
                    <input name="s_count" type="number" class="weui-input" placeholder="请设置数量" value="1"/>
                </div>
            </div>
        </div>
        <div class="weui-cells bg-f7">
            <div class="weui-cell weui-cell_access" id="but_add_service_time" data="15">
                <div class="weui-cell__bd">
                    <p>售后保证时间</p>
                </div>
                <a class="weui-cell__ft" href="javascript:;">
                    <span class="cl-3333">15天</span>
                </a>
            </div>
        </div>
        <a href="javascript:;" class="add_btn">添加</a>
    </div>
</div>

<!--add_service_time-->
<div id="page_add_service_time" class="msg_panel">
    <div class="pageControl index bg-f7 pay">
        <div class="nav">
            <div class="msui_navTop">
                <a class="msui_navTop-back" href="javascript:;"><i class="micon-back_fff"></i></a>
                <h1 class="msui_navTop-title">设置售后时间</h1>
            </div>
        </div>
        <div class="weui-cell add">
            <div class="weui-cell__bd add1" style="display:none;">
                <span>15</span>
                天
            </div>
        </div>
        <div class="js-choose">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span class="cl-3333">无售后</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>15天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2" checked="true" />
                    <i class="micon-check1 micon-checked1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>20天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>30天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>45天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>60天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>180天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>360天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
        </div>
    </div>
</div>

<!--goods-->
<div id="page_goods" class="msg_panel">
    <div class="pageControl index bg-f7 add">
        <div class="nav">
            <div class="msui_navTop">
                <a class="msui_navTop-back" href="javascript:;"><i class="micon-back_fff"></i></a>
                <h1 class="msui_navTop-title">添加商品</h1>
            </div>
        </div>
        <div class="weui-cells add2">
            <div class="weui-cell" id="box_add_img">
                <!--<a href="javascript:;"><img src="/static/wechat/images/1.jpg" alt=""/></a>-->
                <a href="javascript:;" class="add_img">上传图片</a>
                <span style="font-size:12px;color:#999;text-indent:10px;">(长按图片删除)</span>
                <input id="add_img_input" style="display:none" type="file" accept="image/*"   file-attr="" />
            </div>
        </div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-label">
                    名称
                </div>
                <div class="weui-cell__bd">
                    <input name="s_name" type="text" class="weui-input" placeholder="请输入商品名称"/>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-label">
                    价格(元)
                </div>
                <div class="weui-cell__bd">
                    <input name="s_price" type="number" class="weui-input" placeholder="请设置单价" value="0"/>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-label">
                    数量
                </div>
                <div class="weui-cell__bd">
                    <input name="s_count" type="number" class="weui-input" placeholder="请设置数量" value="1" />
                </div>
            </div>
        </div>
        <div class="weui-cells bg-f7">
            <div class="weui-cell weui-cell_access" id="but_goods_time" data="0">
                <div class="weui-cell__bd">
                    <p>售后保证时间</p>
                </div>
                <a class="weui-cell__ft" href="javascript:;">
                    <span class="cl-3333">无售后</span>
                </a>
            </div>
        </div>
        <a href="javascript:;" class="add_btn">添加</a>
        <a href="javascript:;" class="so_btn">搜索添加过的商品</a>
    </div>
</div>

<!--goods_time-->
<div id="page_goods_time" class="msg_panel">
    <div class="pageControl index bg-f7 pay">
        <div class="nav">
            <div class="msui_navTop">
                <a class="msui_navTop-back" href="javascript:;"><i class="micon-back_fff"></i></a>
                <h1 class="msui_navTop-title">设置售后时间</h1>
            </div>
        </div>
        <div class="weui-cell add">
            <div class="weui-cell__bd add1" style="display:none;">
                <span>15</span>
                天
            </div>
        </div>
        <div class="js-choose">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span class="cl-3333">无售后</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>15天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2" checked="true" />
                    <i class="micon-check1 micon-checked1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>20天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>30天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>45天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>60天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>180天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <span>360天</span>
                </div>
                <div class="weui-cell__ft">
                    <input type="checkbox" class="weui-check" name="chooseBox" value="pay2">
                    <i class="micon-check1"></i>
                </div>
            </div>
        </div>
    </div>
</div>

<!--goods_so-->
<div id="page_goods_so" class="msg_panel">
    <div class="pageControl index bg-f7 add">
        <div class="nav">
            <div class="msui_navTop">
                <a class="msui_navTop-back" href="javascript:;"><i class="micon-back_fff"></i></a>
                <h1 class="msui_navTop-title">搜索商品</h1>
            </div>
        </div>
        <div class="weui-cell add3 bg-f7">
            <div class="weui-cell__bd">
                <input type="text" class="weui-input" placeholder="搜索" id="goods_so_txt">
                <i class="add_sou" style="right: 2px;" id="goods_so_but"></i>
            </div>
        </div>
        <div class="weui-cells add4" id="goods_so_list">
            <!--<div class="weui-cell">-->
                <!--<div class="weui-label">-->
                    <!--<p class="add5">-->
                        <!--<img src="../static/images/1.jpg" alt="">-->
                    <!--</p>-->
                <!--</div>-->
                <!--<div class="weui-cell__bd">-->
                    <!--<p class="cl-3333 fs07">快递单号快递单号快递单号快递单号快递单号</p>-->
                    <!--<p class="cl-ffa fs07">￥228.00</p>-->
                <!--</div>-->
            <!--</div>-->
        </div>
    </div>
</div>

<!-- loading toast -->
<div id="loadingToast" style="display:none">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast" style="opacity: 1; visibility: visible;">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">加载中...</p>
    </div>
</div>
<div id="iosDialog2" class="js_dialog" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__bd">弹窗内容，告知当前状态、信息和解决方法，描述文字尽量控制在三行内</div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" onclick="$('#iosDialog2').hide();" class="weui-dialog__btn weui-dialog__btn_primary">知道了</a>
        </div>
    </div>
</div>

{/block}


{block name="javascript"}
<script>
//改写原生的对话框
function sAlert(s){
    $('#iosDialog2').show();
    $('#iosDialog2 .weui-dialog__bd').html(s);
}
window.alert = function(s){sAlert(s);}

//合计计算
function order_sum(){
    var tmpSum = 0;
    $('#box_order_list .list1').each(function(){
        var tmpPrice = parseFloat($(this).find('b').text());
        var tmpCount = parseInt($(this).find('span').text());
        if(isNaN(tmpPrice)){
            tmpPrice = 0;
        }
        if(isNaN(tmpCount)){
            tmpCount = 0;
        }
        tmpSum = tmpSum + (tmpPrice*tmpCount);
    });
    $('#box_order_sum').html(tmpSum.toFixed(2));
}

//长按删除图片
function del_uploads_img(o){
    window.t_img = o;
    window.t_uploads = setTimeout(function(){
        if(window.confirm("确定删除?")){
            var formData = new Object();
            formData.img = '/uploads/'+window.t_img.src.split('/uploads/')[1];
            $.ajax({
                url: '{:url("Base/del_upload_img")}' ,
                type: 'POST',
                data: formData,
                dataType:"json",
                success: function (d) {
                    if(d.code==200){
                        window.t_img.parentNode.removeChild(window.t_img);
                    }else{
                        var code = msg.code;
                        $.alert(error_code[code]);
                    }
                },
                error: function (d) {
                    alert('网络异常');
                }
            });

        }
    },666);
}
//取消长按删除图片
function del_uploads_img_clear(){
    window.clearTimeout(window.t_uploads);
}
$('#box_add_img .add_img').click(function(){
    $('#add_img_input').trigger('click');
});
//添加图片
$("#add_img_input").change(function(){
    if($("#box_add_img img").length>2){
        alert('只能添加3张图片');
    }else{
        $('#loadingToast').fadeIn();
        window.setTimeout(function(){
            var formData = new FormData();
            formData.append("type","goods");
            formData.append("img",$("#add_img_input")[0].files[0]);
            $.ajax({
                url: '{:url("Base/get_upload_img")}' ,
                type: 'POST',
                data: formData,
                async: false,
                cache: true,
                contentType: false,
                processData: false,
                dataType:"json",
                error: function (d) {
                    $('#loadingToast').fadeOut();
                    alert('网络异常');
                },
                success: function (d) {
                    $('#loadingToast').fadeOut();
                    if(!d.code){
                        alert(d.msg);
                    }else{
                        $("#box_add_img").prepend('<a href="javascript:;"><img src="'+SCOPE.image_host_url+d.data.path+'" ontouchstart="del_uploads_img(this)" ontouchend="del_uploads_img_clear()" /></a>');
                    }
                }
            });
        },666);

    }
});

function order_product_server_add(){
    var order_id = '{$order.id}';
    var product_id = new Array();
    var product_name = new Array();
    var product_num = new Array();
    var product_price = new Array();
    var product_attr_id = new Array();
    var product_image = new Array();
    var type = new Array();
    var msg = new Array();
    var server_time = new Array();
    var i = 0;

    if( !$('#box_order_list .weui-cell').length ){
        alert('请添加服务或商品');return false;
    }
    $('#box_order_list .weui-cell').each(function(){
        if( !$(this).attr('sid') ){
            if(i==0){
                product_id[i] = $(this).attr('goods_id');
                product_name[i] = $(this).find('.fs07').text();
                product_num[i] = $(this).find('.list1 span').text();
                product_price[i] = $(this).find('.list1 b').text();
                product_attr_id[i] = 0;
                product_image[i] = $(this).attr('goods_img');
                if($(this).attr('goods_id')=='0'){
                    type[i] = 3;
                }else{
                    type[i] = 2;
                }
                msg[i] = '';
                server_time[i] = $(this).attr('expires_day');
                i++;
                window.order_product_server_box = $(this);
            }else{
                $(this).remove();
            }
        }
    });

    if(product_name.length){
        $('#loadingToast').fadeIn();
        $.ajax({
            type: 'POST',
            url: '{:url("order_product_server_deal_add")}',
            data: {
                order_id: '{$order.id}',
                repair_id: '{$order.repair_id}',
                product_id: product_id[0],
                product_name: product_name[0],
                product_num: product_num[0],
                product_price: product_price[0],
                product_attr_id: product_attr_id[0],
                product_image: product_image[0],
                type: type[0],
                msg: msg[0],
                server_time: server_time[0]
            },
            dataType: 'json',
            error: function (d) {
                $('#loadingToast').fadeOut();
                alert('网络异常');
            },
            success: function (d) {
                $('#loadingToast').fadeOut();
                if(d.code==200){
                    //var tmpUrl = '{:url("r_orders/server_order_goods")}?order_id={$order.id}';
                    //window.location.href = tmpUrl;
                    window.order_product_server_box.attr("sid",d.data);
                    order_sum();
                }else{
                    window.order_product_server_box.remove();
                    var code = d.code;
                    $.alert(error_code[code]);
                }
            }
        });
    }

}


function order_product_server_update(sID,sCount){

    $('#loadingToast').fadeIn();
    $.ajax({
        type: 'POST',
        url: '{:url("order_product_server_deal_update")}',
        data: {
            id: sID,
            order_id: '{$order.id}',
            product_num: sCount
        },
        dataType: 'json',
        error: function (d) {
            $('#loadingToast').fadeOut();
            alert('网络异常');
        },
        success: function (d) {
            $('#loadingToast').fadeOut();
            if(d.code==200){
                //var tmpUrl = '{:url("r_orders/server_order_goods")}?order_id={$order.id}';
                //window.location.href = tmpUrl;
                window.order_product_server_box_count.html(d.data);
                order_sum();
            }else{
                var code = d.code;
                $.alert(error_code[code]);
            }
        }
    });
}

function order_product_server_delete(sID){

    $('#loadingToast').fadeIn();
    $.ajax({
        type: 'POST',
        url: '{:url("order_product_server_deal_delete")}',
        data: {
            id: sID,
            order_id: '{$order.id}'
        },
        dataType: 'json',
        error: function (d) {
            $('#loadingToast').fadeOut();
            alert('网络异常');
        },
        success: function (d) {
            $('#loadingToast').fadeOut();
            if(d.code==200){
                window.order_product_server_box.remove();
                order_sum();
            }else{
                var code = d.code;
                $.alert(error_code[code]);
            }
        }
    });
}

$(function(){

    order_sum();

    //点确认推送
    $('#order_submit_but').click(function(){
        if(!$('#box_order_list .weui-cell').length){
            alert('请添加商品');return false;
        }
        $('#loadingToast').fadeIn();
        $.ajax({
            type: 'POST',
            url: '{:url("repair_deal_push")}',
            data: {
                order_id: '{$order.id}',
                repair_id: '{$order.repair_id}'
            },
            dataType: 'json',
            error: function (d) {
                $('#loadingToast').fadeOut();
                alert('网络异常');
            },
            success: function (d) {
                $('#loadingToast').fadeOut();
                if(d.code==200){
                    var tmpUrl = '{:url("r_orders/server_deal_goods")}?order_id={$order.id}';
                    window.location.href = tmpUrl;
                }else{
                    var code = d.code;
                    $.alert(error_code[code]);
                }
            }
        });

    });



    //点击删除某项
    $(document).on('click', '#box_order_list .weui-cell__ft.list2', function () {
        window.order_product_server_box = $(this).parents('.weui-cell');
        order_product_server_delete($(this).parents('.weui-cell').attr('sid'));
    });
    //点击选择搜索出来的某个商品
    $(document).on('click', '#goods_so_list .weui-cell', function () {
        var goods_id = $(this).attr("goods_id");
        var tmpData = window.soData[goods_id];
        $('#page_goods input[name="s_name"]').val(tmpData.name);
        $('#page_goods input[name="s_price"]').val(tmpData.price);
        $('#page_goods input[name="s_count"]').val(1);
        $('#page_goods #but_goods_time').attr('data',tmpData.service_expires);
        var tmpDay = tmpData.service_expires?tmpData.service_expires+'天':'无售后';
        $('#page_goods #but_goods_time .cl-3333').html(tmpDay);
        $('#box_add_img img').remove();
        var tmpImg = '';
        if(tmpData.img5){
            tmpImg += '<a href="javascript:;"><img src="'+tmpData.img5+'" ontouchstart="del_uploads_img(this)" ontouchend="del_uploads_img_clear()" /></a>';
        }
        if(tmpData.img4){
            tmpImg += '<a href="javascript:;"><img src="'+tmpData.img4+'" ontouchstart="del_uploads_img(this)" ontouchend="del_uploads_img_clear()" /></a>';
        }
        if(tmpData.img3){
            tmpImg += '<a href="javascript:;"><img src="'+tmpData.img3+'" ontouchstart="del_uploads_img(this)" ontouchend="del_uploads_img_clear()" /></a>';
        }
        if(tmpData.img2){
            tmpImg += '<a href="javascript:;"><img src="'+tmpData.img2+'" ontouchstart="del_uploads_img(this)" ontouchend="del_uploads_img_clear()" /></a>';
        }
        if(tmpData.img1){
            tmpImg += '<a href="javascript:;"><img src="'+tmpData.img1+'" ontouchstart="del_uploads_img(this)" ontouchend="del_uploads_img_clear()" /></a>';
        }
        $('#box_add_img').prepend(tmpImg);

        $('#page_goods_so').animate({"left":"100%"});

    });

    //点击number文本框全选数字
    $('input[type="number"]').focus(function(){
        $(this)[0].select();
    });

    //点返回关闭面板
    $('.msui_navTop-back').click(function(){
        $(this).parents('.msg_panel').animate({"left":"100%"});
    });

    //点添加服务
    $('#but_add_service').click(function(){
        $('#page_add_service').animate({"left":"0px"});
    });
    //点添加服务的售后时间
    $('#page_add_service #but_add_service_time').click(function(){
        $('#page_add_service_time').animate({"left":"0px"});
    });
    //选择添加服务的售后时间
    $('#page_add_service_time .index .js-choose .weui-cell').on('click',function(){
        $('#page_add_service_time .index .js-choose i').each(function(){
            if($(this).hasClass('micon-checked1')){
                $(this).removeClass('micon-checked1');
                $(this).prev('input').removeAttr('checked');
            }
        })
        var t=$(this).find('span').html();
        $('#but_add_service_time .cl-3333').html(t);
        var n=parseFloat(t);
        if(isNaN(n)){n=0;}
        $('#but_add_service_time').attr("data",n);
        $('.add1 span').html(n);
        $(this).find('i').addClass('micon-checked1');
        $(this).find('input').attr('checked',true);
        $('#page_add_service_time').animate({"left":"100%"});
    })
    //点添加服务的添加
    $('#page_add_service .add_btn').click(function(){

        var s_name = $('#page_add_service input[name="s_name"]').val();
        var s_price = parseFloat($('#page_add_service input[name="s_price"]').val());
        var s_count = parseInt($('#page_add_service input[name="s_count"]').val());
        var s_service_expires = parseInt($('#page_add_service #but_add_service_time').attr('data'));
        var s_img1 = "/static/wechat/images/fuwu.png";
        if(s_name.length<2){
            alert('请输入完整商品名称');return false;
        }
        if( isNaN(s_price) ){
            alert('请输入数字价格');return false;
        }
        if( parseFloat(s_price)<=0 ){
            alert('价格不正确');return false;
        }
        if( isNaN(s_count) ){
            alert('请输入数字数量');return false;
        }
        if( parseInt(s_count)<=0 ){
            alert('数量不正确');return false;
        }
        if( isNaN(s_service_expires) ){
            alert('请输入数字售后时间');return false;
        }
        if(s_img1==""){
            alert('请至少上传一张图片');return false;
        }

        if( $('#box_order_list div[title="'+s_name+'"]').length ) {
            var nowCount = parseInt($('#box_order_list div[title="'+s_name+'"] .list1 .cl-9999 span').text());
            if(isNaN(nowCount)){
                nowCount = s_count;
            }else{
                nowCount = s_count + nowCount;
            }
            window.order_product_server_box_count = $('#box_order_list div[title="'+s_name+'"] .list1 .cl-9999 span');
            order_product_server_update($('#box_order_list div[title="'+s_name+'"]').attr('sid'),nowCount);
        }else{
            var tmpHtml = '<div class="weui-cell" ' +
                    ' sid=""' +
                    ' goods_id="0"' +
                    ' goods_img="'+s_img1+'"' +
                    ' expires_day="'+s_service_expires+'"' +
                    ' title="'+s_name+'"' +
                    '>' +
                    '<div class="weui-label">' +
                    '<img src="'+s_img1+'" alt=""/>' +
                    '</div>' +
                    '<div class="weui-cell__bd weui-cell__bd1">' +
                    '<p class="fs07">'+s_name+'</p>' +
                    '<p>售后保证'+(s_service_expires?s_service_expires+'天':'无售后')+'</p>' +
                    '</div>' +
                    '<div class="weui-cell__ft list1">' +
                    '<p>￥<b>'+s_price.toFixed(2)+'</b></p>' +
                    '<p class="cl-9999">× <span>'+s_count+'</span></p>' +
                    '</div>' +
                    '<a href="javascript:;" class="weui-cell__ft list2">' +
                    '<span class="fs22">-</span>' +
                    '</a>' +
                    '</div>';
            $('#box_order_list').append(tmpHtml);
            order_product_server_add();
        }

//        $('#page_add_service input[name="s_name"]').val('');
//        $('#page_add_service input[name="s_price"]').val('');
//        $('#page_add_service input[name="s_count"]').val(1);
//        $('#page_add_service #but_add_service_time').attr('data','0');
//        $('#page_add_service #but_add_service_time .cl-3333').html('无售后');
        $('#page_add_service').animate({"left":"100%"});

    });


    //点添加商品
    $('#but_goods').click(function(){
        $('#page_goods').animate({"left":"0px"});
    });
    //点添加商品的售后时间
    $('#page_goods #but_goods_time').click(function(){
        $('#page_goods_time').animate({"left":"0px"});
    });
    //选择添加商品的售后时间
    $('#page_goods_time .index .js-choose .weui-cell').on('click',function(){
        $('#page_goods_time .index .js-choose i').each(function(){
            if($(this).hasClass('micon-checked1')){
                $(this).removeClass('micon-checked1');
                $(this).prev('input').removeAttr('checked');
            }
        })
        var t=$(this).find('span').html();
        $('#but_goods_time .cl-3333').html(t);
        var n=parseFloat(t);
        if(isNaN(n)){n=0;}
        $('#but_goods_time').attr("data",n);
        $('.add1 span').html(n);
        $(this).find('i').addClass('micon-checked1');
        $(this).find('input').attr('checked',true);
        $('#page_goods_time').animate({"left":"100%"});
    })
    //点添加商品的添加
    $('#page_goods .add_btn').click(function(){

        var s_name = $('#page_goods input[name="s_name"]').val();
        var s_price = parseFloat($('#page_goods input[name="s_price"]').val());
        var s_count = parseInt($('#page_goods input[name="s_count"]').val());
        var s_service_expires = parseInt($('#page_goods #but_goods_time').attr('data'));
        s_img1 = s_img2 = s_img3 = s_img4 = s_img5 = "";
        for(i=0;i<$("#box_add_img img").length;i++){
            try{
                eval("s_img"+(i+1)+" = '/uploads/"+$("#box_add_img img")[i].src.split('/uploads/')[1]+"';");
            }catch(e){}
        }
        if(s_name.length<2){
            alert('请输入完整商品名称');return false;
        }
        if( isNaN(s_price) ){
            alert('请输入数字价格');return false;
        }
        if( parseFloat(s_price)<=0 ){
            alert('价格不正确');return false;
        }
        if( isNaN(s_count) ){
            alert('请输入数字数量');return false;
        }
        if( parseFloat(s_price)<=0 ){
            alert('数量不正确');return false;
        }
        if( isNaN(s_service_expires) ){
            alert('请输入数字售后时间');return false;
        }
        if(s_img1==""){
            alert('请至少上传一张图片');return false;
        }

        $('#loadingToast').fadeIn();
        $.ajax({
            type: 'POST',
            url: '{:url("add_product")}',
            data: {
                repair_id: '{$order.repair_id}',
                name: s_name,
                price: s_price,
                service_expires: s_service_expires,
                img1: s_img1,
                img2: s_img2,
                img3: s_img3,
                img4: s_img4,
                img5: s_img5
            },
            dataType: 'json',
            error: function (d) {
                $('#loadingToast').fadeOut();
                alert('网络异常');
            },
            success: function (d) {
                $('#loadingToast').fadeOut();

                if( $('#box_order_list div[goods_id="'+d.data.id+'"]').length ) {
                    var nowCount = parseInt($('#box_order_list div[goods_id="'+d.data.id+'"] .list1 .cl-9999 span').text());
                    if(isNaN(nowCount)){
                        nowCount = s_count
                    }else{
                        nowCount = s_count + nowCount;
                    }
                    window.order_product_server_box_count = $('#box_order_list div[goods_id="'+d.data.id+'"] .list1 .cl-9999 span');
                    order_product_server_update($('#box_order_list div[goods_id="'+d.data.id+'"]').attr('sid'),nowCount);
                }else{
                    var tmpHtml = '<div class="weui-cell" ' +
                            ' sid=""' +
                            ' goods_id="'+d.data.id+'"' +
                            ' goods_img="'+d.data.img+'"' +
                            ' expires_day="'+s_service_expires+'"' +
                            '>' +
                            '<div class="weui-label">' +
                            '<img src="'+d.data.img+'" alt=""/>' +
                            '</div>' +
                            '<div class="weui-cell__bd weui-cell__bd1">' +
                            '<p class="fs07">'+s_name+'</p>' +
                            '<p>售后保证'+(s_service_expires?s_service_expires+'天':'无售后')+'</p>' +
                            '</div>' +
                            '<div class="weui-cell__ft list1">' +
                            '<p>￥<b>'+s_price.toFixed(2)+'</b></p>' +
                            '<p class="cl-9999">× <span>'+s_count+'</span></p>' +
                            '</div>' +
                            '<a href="javascript:;" class="weui-cell__ft list2">' +
                            '<span class="fs22">-</span>' +
                            '</a>' +
                            '</div>';
                    $('#box_order_list').append(tmpHtml);
                    order_product_server_add();
                }

//                $('#page_goods input[name="s_name"]').val('');
//                $('#page_goods input[name="s_price"]').val('');
//                $('#page_goods input[name="s_count"]').val(1);
//                $('#page_goods #but_goods_time').attr('data','0');
//                $('#page_goods #but_goods_time .cl-3333').html('无售后');
//                $('#box_add_img .img').remove();

                $('#page_goods').animate({"left":"100%"});
            }
        });

    });


    //点搜索添加过的商品
    $('#page_goods .so_btn').click(function(){
        $('#page_goods_so').animate({"left":"0"});
    });
    //点搜索
    $('#page_goods_so #goods_so_but').click(function(){
        var tmpKeyword = $('#page_goods_so #goods_so_txt').val();
        $('#loadingToast').fadeIn();
        $.ajax({
            type: 'POST',
            url: '{:url("goods_so")}',
            data: {
                repair_id: '{$order.repair_id}',
                keyword: tmpKeyword
            },
            dataType: 'json',
            error: function (d) {
                $('#loadingToast').fadeOut();
                alert('网络异常');
            },
            success: function (d) {
                $('#loadingToast').fadeOut();
                var tmpHtml = '';
                if(d.code==200){
                    window.soData = new Array();
                    for(i=0;i<d.data.length;i++){
                        tmpHtml += '<a class="weui-cell" href="javascript:;" goods_id="'+d.data[i].id+'">' +
                                '<div class="weui-label"><p class="add5"><img src="'+d.data[i].img1+'" alt="" /></p></div>' +
                                '<div class="weui-cell__bd"><p class="cl-3333 fs07">'+d.data[i].name+'</p><p class="cl-ffa fs07">￥'+d.data[i].price+'</p></div>' +
                                '</a>';
                        window.soData[d.data[i].id] = d.data[i];
                    }
                }else{
                    tmpHtml = '<p align="center" style="line-height:50px;">'+d.msg+'</p>';
                }
                $('#goods_so_list').html(tmpHtml);
            }
        });
    });


});
</script>
{/block}